<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Admin extends CI_Controller {

    function __construct() { //import class
        parent::__construct();
        $this->load->helper('form', 'url');
        $this->load->model('all');
    }

    function tru() { //cek session login
        $log = $this->session->userdata('log');
        $as = $this->session->userdata('as');
        if (!isset($log) || $log != TRUE and $as != TRUE) {
            redirect('admin/index');
        }
    }

    function index() {
        $this->load->view('template/head');
        $this->load->view('admin/content');
        $this->load->view('template/end');
    }

    function amikom() { //login dengan database amikom
        $this->load->library('xmlrpc');
        $this->xmlrpc->server('http://www.amikom.ac.id/index.php/service/');
        $this->xmlrpc->method('login');
        $data['nim'] = $this->input->post('nim');
        $data['password'] = $this->input->post('password');
        $request = array(
            $nim = $this->security->xss_clean($data['nim']),
            $password = $this->security->xss_clean($data['password'])
        );
        $this->xmlrpc->set_debug(false);
        $this->xmlrpc->request($request);
        $this->xmlrpc->send_request();
    }

    function login() {
        $query = $this->all->login();
        if ($query) {
            $user = array(
                'nim' => $this->input->post('nim'),
                'log' => TRUE,
                'admin' => TRUE
            );
            $this->session->set_userdata($user);
            redirect('admin/home');
        } else {
            $this->index();
        }
    }

    function home() { //halaman home
        $this->tru();
        $iased['daaa'] = $this->all->nama();
        $aw['info'] = $this->all->info();
        $asd['rangking'] = $this->all->rangking();
        $this->load->view('template/head');
        $this->load->view('admin/home');
        $this->load->view('admin/right', $iased);
        $this->load->view('admin/info', $aw);
        $this->load->view('admin/rangking', $asd);
        $this->load->view('admin/menu');
        $this->load->view('template/end');
    }

    function profile() {
        $this->tru();
        $iased['daaa'] = $this->all->nama();
        $aw['info'] = $this->all->info();
        $asd['rangking'] = $this->all->rangking();
        $ds['profil'] = $this->all->profile();
        $this->load->view('template/head');
        $this->load->view('admin/profile', $ds);
        $this->load->view('admin/right', $iased);
        $this->load->view('admin/info', $aw);
        $this->load->view('admin/rangking', $asd);
        $this->load->view('admin/menu');
        $this->load->view('template/end');
    }

    function logout() { //logout
        $this->tru();
        $this->session->unset_userdata('nim');
        $this->session->unset_userdata('log_in');
        redirect('admin');
    }

    function pswd() {
        $this->tru();
        $this->all->password();
        redirect('admin/suc');
    }

    function suc() {
        $this->tru();
        $iased['daaa'] = $this->all->nama();
        $aw['info'] = $this->all->info();
        $asd['rangking'] = $this->all->rangking();
        $this->load->view('template/head');
        $this->load->view('admin/success');
        $this->load->view('admin/right', $iased);
        $this->load->view('admin/info', $aw);
        $this->load->view('admin/rangking', $asd);
        $this->load->view('admin/menu');
        $this->load->view('template/end');
    }

    function showtime() {
        $this->tru();
        $iased['daaa'] = $this->all->nama();
        $aw['info'] = $this->all->info();
        $asd['rangking'] = $this->all->rangking();
        $sh['show'] = $this->all->showtime();
        $this->load->view('template/head');
        $this->load->view('admin/settime', $sh);
        $this->load->view('admin/right', $iased);
        $this->load->view('admin/info', $aw);
        $this->load->view('admin/rangking', $asd);
        $this->load->view('admin/menu');
        $this->load->view('template/end');
    }
    
    function settime(){
        $this->tru();
        $this->all->settime();
        redirect('admin/setsuc');
    }
    
    function setsuc() {
        $this->tru();
        $iased['daaa'] = $this->all->nama();
        $aw['info'] = $this->all->info();
        $asd['rangking'] = $this->all->rangking();
        $this->load->view('template/head');
        $this->load->view('admin/setsuccess');
        $this->load->view('admin/right', $iased);
        $this->load->view('admin/info', $aw);
        $this->load->view('admin/rangking', $asd);
        $this->load->view('admin/menu');
        $this->load->view('template/end');
    }
    
    function statistic(){
        $this->tru();
        $iased['daaa'] = $this->all->nama();
        $aw['info'] = $this->all->info();
        $asd['rangking'] = $this->all->rangking();
        $list['rangking'] = $this->all->rangking();
        $list['qtyvst'] = $this->all->qtyvst();
        $list['lastip'] = $this->all->lastip();
        $list['online'] = $this->all->online();
        $this->load->view('template/head');
        $this->load->view('admin/statistic', $list);
        $this->load->view('admin/right', $iased);
        $this->load->view('admin/info', $aw);
        $this->load->view('admin/rangking', $asd);
        $this->load->view('admin/menu');
        $this->load->view('template/end');
    }

    function result(){
        $this->tru();
        $iased['daaa'] = $this->all->nama();
        $aw['info'] = $this->all->info();
        $asd['rangking'] = $this->all->rangking();
        $list['pol'] = $this->all->kand1();
        $list['rst'] = $this->all->kand2();
        $this->load->view('template/head');
        $this->load->view('admin/result', $list);
        $this->load->view('admin/right', $iased);
        $this->load->view('admin/info', $aw);
        $this->load->view('admin/rangking', $asd);
        $this->load->view('admin/menu');
        $this->load->view('template/ends');
    }
}

/* End of file admin.php */
/* Location: ./application/controllers/admin.php */